﻿using System;
using System.Collections.Generic;

namespace Adalbertus.BudgetPlanner.Domain
{
    public class Saving
    {
        public virtual int Id { get; private set; }

        public virtual string Name { get; set; }
        public virtual IList<SavingEntry> Entries { get; private set; }

        public Saving()
        {
            Entries = new List<SavingEntry>();
        }

        public virtual SavingEntry Withdraw(decimal savingValue, DateTime date)
        {
            SavingEntry newEntry = new SavingEntry
            {
                Saving = this,
                Date = date,
                Value = -savingValue,
            };
            Entries.Add(newEntry);
            return newEntry;
        }

        public virtual void Deposit(decimal savingValue, DateTime date)
        {
            Entries.Add(new SavingEntry
            {
                Date = date,
                Value = savingValue,
                Saving = this,
            }
            );
        }
    }
}
